<?php

/**
 * @name 		CMS Helper
 * @author 		SimpleCMS Development Team
 * @package 	SimpleCMS
 * @subpackage 	Helpers
 */

// ------------------------------------------------------------------------

if ( ! function_exists('is_ajax'))
{
	function is_ajax()
	{
		return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
	}
}

if ( ! function_exists('cms_setting'))
{
	function cms_setting($setting)
	{
		$CI =& get_instance();

		$CI->load->model('setting_model');

		echo $setting = $CI->setting_model->get($setting);
	}
}

if ( ! function_exists('cms_return_setting'))
{
	function cms_return_setting($setting)
	{
		$CI =& get_instance();

		$CI->load->model('setting_model');

		$setting = $CI->setting_model->get($setting);
		if ($setting=='') return false;
		return $setting;
	}
}

if(! function_exists('cms_check_var'))
{
    function cms_check_var($var, $open_tag = '', $close_tag = '')
    {
        if(isset($var))
        {
            if($var != '' AND $var !== FALSE AND $var != 0)
            {
                return $open_tag.$var.$close_tag;
            }
        }
        return FALSE;
    }
}
if(! function_exists('my_date_format'))
{
 //date format
    function my_date_format($date_string, $format = 'Y-m-d')
    {
        if($date_string == '')
        {
            return NULL;
        }
        $new_format = date($format, strtotime($date_string));
        return $new_format;
    }
}

if(! function_exists('day_diff'))
{
    function day_diff($subdate, $mindate = NULL)
    {
        $day = 60*60*24;
        if(!$mindate)
        {
            $mindate = time();//current timestamp
        }
        else
        {
            $mindate = strtotime($mindate);
        }
        
        $days = floor(($mindate - strtotime($subdate)) / $day);
        return $days;
    }
}

if ( ! function_exists('feedback'))
{
	function feedback($message = '', $prefix = '', $suffix = '')
	{
		if ($message AND  ! empty($message))
		{
			return $prefix . $message . $suffix;
		}
		return;
	}
}

if(! function_exists('cms_country_dropdown'))
{
    function cms_country_dropdown($form_name = 'country', $selected_value = '')
    {
	$countries_array = cms_countries_array();
	$countries = array();
	$countries[''] = '- - Please Select - -';
	foreach($countries_array as $country)
	{
	    $countries[$country] = $country;
	}

	echo form_dropdown($form_name, $countries, $selected_value,'id="country"');
    }
}

if(! function_exists('cms_countries_array'))
{
    function cms_countries_array()
    {
	$country_list = array(
		"Afghanistan",
		"Albania",
		"Algeria",
		"Andorra",
		"Angola",
		"Antigua and Barbuda",
		"Argentina",
		"Armenia",
		"Australia",
		"Austria",
		"Azerbaijan",
		"Bahamas",
		"Bahrain",
		"Bangladesh",
		"Barbados",
		"Belarus",
		"Belgium",
		"Belize",
		"Benin",
		"Bhutan",
		"Bolivia",
		"Bosnia and Herzegovina",
		"Botswana",
		"Brazil",
		"Brunei",
		"Bulgaria",
		"Burkina Faso",
		"Burundi",
		"Cambodia",
		"Cameroon",
		"Canada",
		"Cape Verde",
		"Central African Republic",
		"Chad",
		"Chile",
		"China",
		"Colombi",
		"Comoros",
		"Congo (Brazzaville)",
		"Congo",
		"Costa Rica",
		"Cote d'Ivoire",
		"Croatia",
		"Cuba",
		"Cyprus",
		"Czech Republic",
		"Denmark",
		"Djibouti",
		"Dominica",
		"Dominican Republic",
		"East Timor (Timor Timur)",
		"Ecuador",
		"Egypt",
		"El Salvador",
		"Equatorial Guinea",
		"Eritrea",
		"Estonia",
		"Ethiopia",
		"Fiji",
		"Finland",
		"France",
		"Gabon",
		"Gambia, The",
		"Georgia",
		"Germany",
		"Ghana",
		"Greece",
		"Grenada",
		"Guatemala",
		"Guinea",
		"Guinea-Bissau",
		"Guyana",
		"Haiti",
		"Honduras",
		"Hungary",
		"Iceland",
		"India",
		"Indonesia",
		"Iran",
		"Iraq",
		"Ireland",
		"Israel",
		"Italy",
		"Jamaica",
		"Japan",
		"Jordan",
		"Kazakhstan",
		"Kenya",
		"Kiribati",
		"Korea, North",
		"Korea, South",
		"Kuwait",
		"Kyrgyzstan",
		"Laos",
		"Latvia",
		"Lebanon",
		"Lesotho",
		"Liberia",
		"Libya",
		"Liechtenstein",
		"Lithuania",
		"Luxembourg",
		"Macedonia",
		"Madagascar",
		"Malawi",
		"Malaysia",
		"Maldives",
		"Mali",
		"Malta",
		"Marshall Islands",
		"Mauritania",
		"Mauritius",
		"Mexico",
		"Micronesia",
		"Moldova",
		"Monaco",
		"Mongolia",
		"Morocco",
		"Mozambique",
		"Myanmar",
		"Namibia",
		"Nauru",
		"Nepa",
		"Netherlands",
		"New Zealand",
		"Nicaragua",
		"Niger",
		"Nigeria",
		"Norway",
		"Oman",
		"Pakistan",
		"Palau",
		"Panama",
		"Papua New Guinea",
		"Paraguay",
		"Peru",
		"Philippines",
		"Poland",
		"Portugal",
		"Qatar",
		"Romania",
		"Russia",
		"Rwanda",
		"Saint Kitts and Nevis",
		"Saint Lucia",
		"Saint Vincent",
		"Samoa",
		"San Marino",
		"Sao Tome and Principe",
		"Saudi Arabia",
		"Senegal",
		"Serbia and Montenegro",
		"Seychelles",
		"Sierra Leone",
		"Singapore",
		"Slovakia",
		"Slovenia",
		"Solomon Islands",
		"Somalia",
		"South Africa",
		"Spain",
		"Sri Lanka",
		"Sudan",
		"Suriname",
		"Swaziland",
		"Sweden",
		"Switzerland",
		"Syria",
		"Taiwan",
		"Tajikistan",
		"Tanzania",
		"Thailand",
		"Togo",
		"Tonga",
		"Trinidad and Tobago",
		"Tunisia",
		"Turkey",
		"Turkmenistan",
		"Tuvalu",
		"Uganda",
		"Ukraine",
		"United Arab Emirates",
		"United Kingdom",
		"United States",
		"Uruguay",
		"Uzbekistan",
		"Vanuatu",
		"Vatican City",
		"Venezuela",
		"Vietnam",
		"Yemen",
		"Zambia",
		"Zimbabwe"
	);
	return $country_list;
    }
}
?>